package com.sias.mianshiya.aop;

import com.sias.mianshiya.annotation.IsLogin;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 吴文杰
 * @version 1.0
 * @since 2025/2/7 22:39
 */
@Aspect
@Component
public class IsLoginInterceptor {
  // region 第一
  String test;
  // endregion

  // region 第二
  // endregion
  public void test(){

  }

  // region login

  @Around("@annotation(isLogin)")
  public Object doInterceptor(ProceedingJoinPoint point, IsLogin isLogin) throws Throwable {
    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
    String requestURI = request.getRequestURI();
    System.out.println(requestURI+"asdasdadasd32as1d321asd");
    return point.proceed();
  }

  // endregion
}
